
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="attendance/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="attendance/css/commonly-used-show.css" />
    <script type="text/javascript" src="attendance/js/jquery.min.js"></script>
    <script type="text/javascript" src="attendance/js/bootstrap.js" ></script>

    <title>管理课程</title>

</head>

<body class="mybody">

 <jsp:include page="theTopMenuUser.jsp" />

 <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">

                            <div class="container">
    <div style="margin-left: 10px; margin-right: 10px;" >
        <h3 style="text-align: center">管理课程</h3>
        <hr style="filter: alpha(opacity=100,finishopacity=0,style=3)" width="100%" color="#6f5999" size="3" />


        <div class="row" id="take_course">

            </div>


    </div>
 </div>

                        </div>
                    </div>
                </div>
        </div>




<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }


    window.onload = function(){
        courseAllInfo();
    }

    function courseAllInfo(){
        var postUrl = "${pageContext.request.contextPath}/member/queryStudentCourseInfoAll";

        var str = {
            "studentId": userdt.result.id,
            "selectedState": "1"
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){

                if (data.status == "0"){
                    noDate();
                }else {
                    var strtab = "";
                    var jumpUrl = "#";
                    var imgUrl = "";
                    var butCourse = "";

                    if (data.result.length !== 0){
                        for (var i = 0; i < data.result.length; i++){

                            if (data.result[i].classPictures != null){
                                imgUrl = "${pageContext.request.contextPath}" + data.result[i].classPictures;
                            }else {
                                imgUrl = "attendance/img/no_date.jpeg";
                            }

                            butCourse = "<button style=\"float: right;\" onclick='join(" + data.result[i].id + ")' class=\"btn btn-success\">退出课程</button>";

                            strtab = "<div class=\"col-md-3\">\n" +
                                "                    <div class=\"panel panel-primary\">\n" +
                                "                        <div style=\"margin: 10px\">\n" +
                                "                            <a href='" + jumpUrl + "'><img src='" + imgUrl + "' width=\"230px\" height=\"270px\"></a>\n" +
                                "                            <div style=\"margin-left: 5px; margin-top: 5px; margin-bottom: 25px;\">\n" +
                                "                                <p style=\"font-size: 16px\">" + data.result[i].courseTitle + "</p>\n" +
                                "                                <span style=\"font-size: 14px\">" + data.result[i].instructor + "</span>\n" +
                                "                                " + butCourse +
                                "                            </div>\n" +
                                "                        </div>\n" +
                                "                    </div>\n" +
                                "                </div>";
                            $("#take_course").append(strtab);

                        }
                    }else {
                        noDate();
                    }

                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }


    function join(id){
        var postUrl = "${pageContext.request.contextPath}/member/updateCourse";
        var str = {
            "id": id,
            "studentId": userdt.result.id,
            "selectedState": "0"
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    alert(data.msg);
                }else {
                    location.reload();
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

    function noDate(){
        var strtably = "";
        strtably = "<div class=\"col-md-3\">\n" +
            "                    <div class=\"panel panel-primary\">\n" +
            "                        <div style=\"margin: 10px\">\n" +
            "                            <a href=\"#\"><img src=\"attendance/img/no_date.jpeg\" width=\"230px\" height=\"270px\"></a>\n" +
            "                            <div style=\"margin-left: 5px; margin-top: 5px;  margin-bottom: 25px;\">\n" +
            "                                <p style=\"font-size: 16px\">暂无数据</p>\n" +
            "                                <span style=\"font-size: 14px\">暂无数据</span>\n" +
            "                                <button id='mybut' style=\"float: right;\" class=\"btn btn-success\">暂无数据</button>\n" +
            "                            </div>\n" +
            "                        </div>\n" +
            "                    </div>\n" +
            "                </div>";
        $("#take_course").append(strtably);
    }

</script>

</body>
</html>
</span>